//
//  atomic.h
//  medusa
//
//  Created by gww on 13-4-23.
//  Copyright (c) 2013年 Bullets in a Burning Box, Inc. All rights reserved.
//

#ifndef __MEDUSA_ATOMIC_HPP__
#define __MEDUSA_ATOMIC_HPP__

#include "../MedusaMacros.h"


NS_MEDUSA_BEGIN

template<typename T> class Atomic {
    
public:
    
    Atomic(T val) {
        
    }
    T FetchAndAdd (T value);
    T FetchAndSub (T value);
    T FetchAndOr (T value);
    T FetchAndAnd (T value);
    T FetchAndXor (T value);
    T FetchAndNand (T value);
    
    T AddAndFetch (T value);
    T SubAndFetch (T value);
    T OrAndFetch (T value);
    T AndAndFetch (T value);
    T XorAndFetch (T value);
    T NandAndFetch (T value);
    
private:
    T val;

};


class AtomicBoolean {
    
public:
    
    AtomicBoolean(bool val=false) {
        this->val = val;
    }
    
    bool Get() const {
        return this->val;
    }
    
    void Set(bool val) {
        this->val = val;
    }
    
    bool Swap(bool val) {
        return true;
    }
    
private:
    bool val;
};

class AtomicInt8 {
    
public:
    
    AtomicInt8(uint8_t val=0) {
        this->val = val;
    }
    
    uint8_t Get() const {
        return this->val;
    }
    
    void Set(uint8_t val) {
        this->val = val;
    }
    
private:
    uint8_t val;
};

class AtomicInt16 {
    
public:
    
    AtomicInt16(uint16_t val=0) {
        this->val = val;
    }
    
    uint16_t Get() const {
        return this->val;
    }
    
    void Set(uint16_t val) {
        this->val = val;
    }
    
private:
    uint16_t val;
};

class AtomicInt32 {
    
public:
    
    AtomicInt32(uint32_t val=0) {
        this->val = val;
    }
    
    uint32_t Get() const {
        return this->val;
    }
    
    void Set(uint32_t val) {
        this->val = val;
    }
    
private:
    uint32_t val;
};

class AtomicInt64 {
    
public:
    
    AtomicInt64(uint64_t val=0) {
        this->val = val;
    }
    
    uint64_t Get() const {
        return this->val;
    }
    
    void Set(uint64_t val) {
        this->val = val;
    }
    
private:
    uint64_t val;
};

NS_MEDUSA_END

#endif //__MEDUSA_ATOMIC_HPP__
